package com.wzy.pictureviewfliper;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout.LayoutParams;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private Context mContext;
    private Button mClick;
    private LinearLayout mRoot;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mContext = MainActivity.this;
        mClick = (Button) findViewById(R.id.click_flip);
        mRoot = (LinearLayout) findViewById(R.id.container);
        mClick.setOnClickListener(this);
        int[] imgs = {R.mipmap.email, R.mipmap.mms, R.mipmap.qq, R.mipmap.qzone, R.mipmap.weibo, R.mipmap.weixin, R.mipmap.wxfriend};
        ArrayList<Item> datas = new ArrayList<Item>();
        for (int i = 0; i < 6; i++) {
            Item item = new Item(imgs[i], "柔光自拍" + i);
            datas.add(item);
        }

        for (int i = 0; i < 6; i++) {
            ImageTextFlipper imageTextFlipper = new ImageTextFlipper(mContext);
            imageTextFlipper.setData(datas);
            LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            mRoot.addView(imageTextFlipper, lp);
        }
    }

    @Override
    public void onClick(View v) {
        long delayMillis = 0;
        for (int i = 0; i < mRoot.getChildCount(); i++) {
            View view = mRoot.getChildAt(i);
            if (view instanceof ImageTextFlipper) {
                ((ImageTextFlipper) view).showNext(delayMillis);
                delayMillis += 60;
            }
        }
    }
}
